package zabbix

import (
	"encoding/json"
	"errors"
)

func ScreenCreateData() (string,map[string]interface{}) {
	method := "screen.create"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "name": "Graphs",
        "hsize": 3,
        "vsize": 2,
        "screenitems": [
            {
                "resourcetype": 0,
                "resourceid": "612",
                "rowspan": 1,
                "colspan": 1,
                "x": 0,
                "y": 0
            }
        ]
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func ScreenDeleteData() (string,map[string]interface{}) {
	method := "screen.delete"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "25",
        "26"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func ScreenUpdateData() (string,map[string]interface{}) {
	method := "screen.update"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "screenid": "26",
        "name": "CPU Graphs"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func ScreenGetData() (string,map[string]interface{}) {
	method := "screen.get"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "output": "extend",
        "selectScreenItems": "extend",
        "selectUsers": "extend",
        "selectUserGroups": "extend",
        "screenids": "26"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}



func ScreenCreate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := ScreenCreateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func ScreenDelete(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := ScreenDeleteData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func ScreenUpdate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := ScreenUpdateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func ScreenGet(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := ScreenGetData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}



